package com.alvin.demo.service.impl;

import com.alvin.demo.domain.SysRole;
import com.alvin.demo.domain.SysUser;
import com.alvin.demo.mapper.RoleMapper;
import com.alvin.demo.mapper.UserMapper;
import com.alvin.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;
    @Autowired
    private RoleMapper roleMapper ;

    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        SysUser sysUser = userMapper.findByName(s);
        List<SysRole> sysRoles = roleMapper.findByUid(sysUser.getId());
        sysUser.setRoles(sysRoles);
        return sysUser;
    }

}
